package org.baicaixiaozhan.springbootwebdemo1.util;

import org.baicaixiaozhan.springbootwebdemo1.domain.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * DESC:
 *
 * @author : baicaixiaozhan
 * @since : 2021-01-30
 */
public class HttpUtils {

    public static HttpServletRequest getHttpServletRequest() {
        return ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
    }

    public static void setCurrentLoginUser(User user) {
        getHttpServletRequest().setAttribute("currentUser", user);
    }

    public static User getCurrentLoginUser() {
        return (User) getHttpServletRequest().getAttribute("currentUser");
    }
}
